#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	const int MAX = 350;
	int triangle[MAX][MAX];
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i + 1; j++) {
			scanf("%d", *(triangle + i) + j);
		}
	}
	int result[MAX];
	result[0] = triangle[0][0];
	int left, right, pre;
	for (int i = 1; i < N; i++) {
		pre = 0;
		for (int j = 0; j < i + 1; j++) {
			left = j < 1 ? 0 : pre;
			right = j >= i ? 0 : result[j];

			pre = result[j];
			result[j] = (left >= right ? left : right) + triangle[i][j];
		}
	}

	int max = result[0];
	for (int i = 1; i < N; i++) {
		if (max < result[i])
			max = result[i];
	}
	printf("%d\n", max);

	return 0;
}